package com.ruoyi.web.controller.system;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.KelingPic;
import com.ruoyi.system.service.IKelingPicService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 可灵生成记录Controller
 * 
 * @author ruoyi
 * @date 2024-11-01
 */
@Controller
@RequestMapping("/system/pic")
@Api("图生图")
public class KelingPicController extends BaseController
{
    private String prefix = "system/pic";

    @Autowired
    private IKelingPicService kelingPicService;

    @RequiresPermissions("system:pic:view")
    @GetMapping()
    public String pic()
    {
        return prefix + "/pic";
    }

    /**
     * 查询可灵生成记录列表
     */
    @RequiresPermissions("system:pic:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(KelingPic kelingPic)
    {
        startPage();
        List<KelingPic> list = kelingPicService.selectKelingPicList(kelingPic);
        return getDataTable(list);
    }

    /**
     * 导出可灵生成记录列表
     */
    @RequiresPermissions("system:pic:export")
    @Log(title = "可灵生成记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(KelingPic kelingPic)
    {
        List<KelingPic> list = kelingPicService.selectKelingPicList(kelingPic);
        ExcelUtil<KelingPic> util = new ExcelUtil<KelingPic>(KelingPic.class);
        return util.exportExcel(list, "可灵生成记录数据");
    }

    /**
     * 新增可灵生成记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存可灵生成记录
     */
    @RequiresPermissions("system:pic:add")
    @Log(title = "可灵生成记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(KelingPic kelingPic)
    {
        return toAjax(kelingPicService.insertKelingPic(kelingPic));
    }

    /**
     * 修改可灵生成记录
     */
    @RequiresPermissions("system:pic:edit")
    @GetMapping("/edit/{kelingId}")
    public String edit(@PathVariable("kelingId") Long kelingId, ModelMap mmap)
    {
        KelingPic kelingPic = kelingPicService.selectKelingPicByKelingId(kelingId);
        mmap.put("kelingPic", kelingPic);
        return prefix + "/edit";
    }

    /**
     * 修改保存可灵生成记录
     */
    @RequiresPermissions("system:pic:edit")
    @Log(title = "可灵生成记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(KelingPic kelingPic)
    {
        return toAjax(kelingPicService.updateKelingPic(kelingPic));
    }

    /**
     * 删除可灵生成记录
     */
    @RequiresPermissions("system:pic:remove")
    @Log(title = "可灵生成记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(kelingPicService.deleteKelingPicByKelingIds(ids));
    }


    @ApiOperation("图片生成")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "path", value = "文件夹路径", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "prompt", value = "正向提示词", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "negativePrompt", value = "反向提示词", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "number", value = "生成数量", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "fidelity", value = "参考强度", dataType = "Double", dataTypeClass = Double.class),
            @ApiImplicitParam(name = "count", value = "生成次数", dataType = "Integer", dataTypeClass = Integer.class),
    })
    @PostMapping( "/generations")
    @ResponseBody
    public AjaxResult generations(String path,String prompt,String negativePrompt,Integer number,Double fidelity,Integer count) throws Exception {
        return kelingPicService.generations(path,prompt,negativePrompt, number, fidelity,count);
    }

    @ApiOperation("菜谱生成")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "path", value = "文件夹路径", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "prompt", value = "正向提示词", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "number", value = "生成数量", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "fidelity", value = "参考强度", dataType = "Double", dataTypeClass = Double.class),
            @ApiImplicitParam(name = "count", value = "生成次数", dataType = "Integer", dataTypeClass = Integer.class),
    })
    @PostMapping( "/menumaking")
    @ResponseBody
    public AjaxResult menuMaking(String path,String prompt,Integer number,Double fidelity,Integer count) throws Exception {
        return kelingPicService.menuMaking(path,prompt, number, fidelity,count);
    }
    @ApiOperation("即梦图片生成")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "path", value = "文件夹路径", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "prompt", value = "正向提示词", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "fidelity", value = "参考强度", dataType = "Double", dataTypeClass = Double.class),
            @ApiImplicitParam(name = "count", value = "生成次数", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "picStyle", value = "图片类型", dataType = "String", dataTypeClass = String.class),
    })
    @PostMapping( "/jimenggenerations")
    @ResponseBody
    public AjaxResult jimenggenerations(String path, String prompt,Double fidelity,Integer count,String picStyle) throws Exception {
        return kelingPicService.jiMengGenerations( path,  prompt, fidelity, count, picStyle);
    }

    @ApiOperation("下载保存图片")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "picStyle", value = "图片风格", dataType = "String", dataTypeClass = String.class),
    })
    @PostMapping( "/saveDownPic")
    @ResponseBody
    public AjaxResult saveDownPic(String picStyle) throws Exception {
        return kelingPicService.saveDownPic(picStyle);
    }
}
